﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace GeneralAdaptiveFramework
{
    public class Act : PassiveComponent
    {
        readonly int moveSleepTime = 200;

        public Act(string _name)
            : base(_name)
        {
            initPort();
        }

        /**
         * Init two Provide ports and two Require ports
         */
        private void initPort()
        {
            interfaceList = new ArrayList();

            ProvideInterface provider01 = new ProvideInterface("PAct01", this);
            ProvideInterface provider02 = new ProvideInterface("PAct02", this);
            RequireInterface require01 = new RequireInterface("RAct01", this);
            RequireInterface require02 = new RequireInterface("RAct02", this);

            interfaceList.Add(provider01);
            interfaceList.Add(provider02);
            interfaceList.Add(require01);
            interfaceList.Add(require02);
        }

        private void connect()
        {
        }

        /**
         * Receive data
         */
        public override void receiveData(Object data)
        {
            // add data to buffer
            buffer.Add(data);

            // call execute
            execute();
        }

        public override void execute()
        {
            // get data from buffer
            if (buffer.Count > 0)
            {
                ControlInfo controlInfo = (ControlInfo)buffer[0];
                buffer.RemoveAt(0);
#if DEBUG
                Console.WriteLine(controlInfo.message);
#endif
                //if (controlInfo.message == "Left to find base")
                    //CollectForm.ezB_Connect.EZB.ARDroneControl.PlayLedAnimation(EZ_B.ARDrone.Commands.LedAnimationEnum.BlinkRed, 2, 2);
                //else
                if (controlInfo.message.Contains("ESCAPE"))
                    addComponent("path", "Escape");
                else if (controlInfo.message.Contains("Task completed."))
                {
                    CollectForm.ezB_Connect.EZB.ARDroneControl.Land();
                    CollectForm.turnOffTimer();
                }
                else
                {
                    if (CollectForm.getStart() == false)
                    {
                        CollectForm.setStart(true);
                        //CollectForm.ezB_Connect.EZB.ARDroneControl.TakeOff();
                    }
                }
                ////ezB_Connect.EZB.ARDroneControl.SetProgressiveInputValues(controlInfo.parameters[0], controlInfo.parameters[1], controlInfo.parameters[2], controlInfo.parameters[3]);
                //System.Threading.Thread.Sleep(moveSleepTime);
            }
        }
    }
}
